﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.ModelInterface;
using QLBH.DataModel;
using QLBH.Model.Controller;
using QLBH.ModelFactory;

namespace QLBH.CongNo
{
    public partial class frmThuTraNoHistoryDlg : Form
    {
        private eLoaiNo loaiNo;
        private ISoNoModel sonoModel;

        public ISoNoModel SonoModel
        {            
            set 
            {
                sonoModel = value; 
                if (sonoModel!=null)
                {
                    if (loaiNo==eLoaiNo.LN_KHNO || loaiNo==eLoaiNo.LN_NOKH)
                    {
                        tbxHoTen.Text = sonoModel.TENKH;
                    }
                    else
                    {
                        tbxHoTen.Text = sonoModel.TENNCC;
                    }
                    tbxSoTienNo.Text = sonoModel.SOTIEN.ToString();
                    tbxDaTra.Text = sonoModel.DATRA.ToString();
                    tbxNgayTao.Text = sonoModel.NGAYTAO.ToString();                    
                }
            }
        }
        public frmThuTraNoHistoryDlg(eLoaiNo loaiNo)
        {
            InitializeComponent();

            this.loaiNo = loaiNo;

            switch(loaiNo)
            {
                case eLoaiNo.LN_KHNO:
                case eLoaiNo.LN_NCCNO:
                    this.Text = "Lịch sử thu nợ";
                    break;
                case eLoaiNo.LN_NOKH:
                case eLoaiNo.LN_NONCC:
                    this.Text = "Lịch sử trả nợ";
                    break;
            }
        }

        private void frmThuTraNoHistoryDlg_Load(object sender, EventArgs e)
        {
            LoadHistory();
        }

        private void LoadHistory()
        {
            List<ILichSuThuNoModel> models = new List<ILichSuThuNoModel>();
            List<LICHSUTHUTRANO> histories = LichSuTraNoController.GetInstance().FindBy(e => 
                e.SONOID == sonoModel.SONOID).ToList();

            foreach (LICHSUTHUTRANO item in histories)
            {
                ILichSuThuNoModel his = CongNoModelFactory.GetLichSuThuNoModelInstance();
                his.InitFromEntity(item);

                models.Add(his);
            }

            dataGridViewEx1.DataSource = models;
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }
    }
    public enum eLoaiNo
    {
        LN_KHNO,
        LN_NOKH,
        LN_NCCNO,
        LN_NONCC
    };
}
